There is a pitfall with this function: If you accidentally use Scene as the go argument, your event will be posted to every listener in the scene.
For example:
For example:
protected override void OnParentChanged( GameObject oldParent, GameObject newParent ) { IParentAssignEvents.PostToGameObject( oldParent, x => x.OnUnassigned( this ) ); IParentAssignEvents.PostToGameObject( newParent, x => x.OnAssigned( this ) ); }
To fix this, just verify that either argument is not the Scene before you send the event:
protected override void OnParentChanged( GameObject oldParent, GameObject newParent ) { if (oldParent != Scene) IParentAssignEvents.PostToGameObject( oldParent, x => x.OnUnassigned( this ) ); if (newParent != Scene) IParentAssignEvents.PostToGameObject( newParent, x => x.OnAssigned( this ) ); }